package com.taobaolite.transaction;

import com.taobaolite.user.User;
import org.hibernate.validator.constraints.UniqueElements;

import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Time;
import java.sql.Timestamp;

@Table(name = "transaction")
@Entity
public class Transaction implements Serializable {

    public Transaction(User userFrom, User userTo, Timestamp time, Double total) {
        this.transactionId = new TransactionPK(userFrom, userTo, time);
        this.total = total;
    }

    @EmbeddedId
    @NotNull
    private TransactionPK transactionId;

    @NotNull
    @Min(value = 0)
    @Column(updatable = false)
    private Double total;

    public TransactionPK getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(TransactionPK transactionId) {
        this.transactionId = transactionId;
    }

    public Double getTotal() {
        return total;
    }

    public void setTotal(Double total) {
        this.total = total;
    }

    public Transaction() {}
}